package com.jin.blog.controller;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jin.blog.pojo.Article;
import com.jin.blog.pojo.Project;

public abstract class BaseController extends Controller {

	public void getCommonData(){
		List<Article> hotsView = Article.dao.findByCache("article", "hotsView", "select id,title,viewCount from article where finish = 1 order by viewCount desc limit 0,5");
		setAttr("hotsView", hotsView);
		
//		List<Article> hotsReply = Article.dao.findByCache("article", "hotsReplay", "select id,title,viewCount from article where finish = 1 order by replyCount desc limit 0,10");
//		setAttr("hotsReply", hotsReply);
		
		List<Project> projects = Project.dao.findByCache("project", "top", "select id,name from project order by id desc limit 0,10");
		setAttr("projects", projects);
		
//		List<Message> messages = Message.dao.findByCache("item","recently_messages","select id,email,content,dateTime,nick from message order by id desc limit 0,10"); 
//		setAttr("messages", messages);
		
		Set<String> set = new HashSet<>();
		List<Record>records = Db.find("select tags from article");
		for (Record record : records) {
			String[] strs = record.getStr("tags").split(",");
			for (String tag : strs) {
				set.add(tag);
			}
		}
		setAttr("tags", set);
		
	}
}
